#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 3e5+10;

int nodenum,h[N],ls[N<<5],rs[N<<5],siz[N],dfn[N],tim,fa[N],dep[N],n,q,k,p,cnt,rt[N],u,v;
ll ans,val[N<<5];
struct edge{int v,nxt;}e[N<<1];
void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

void update(int &y,int x,int pos,int v,int l = 1,int r = n){
	y = ++nodenum; ls[y] = ls[x]; rs[y] = rs[x]; val[y] = val[x] + v;
	if(l == r) return;
	int mid = l+r>>1;
	if(pos <= mid) update(ls[y],ls[x],pos,v,l,mid);
	else update(rs[y],rs[x],pos,v,mid+1,r);
}

ll query(int y,int x,int xl,int xr,int l = 1,int r = n){
	if(xl == l && xr == r) return val[y] - val[x];
	int mid = l+r>>1;
	if(xr <= mid) return query(ls[y],ls[x],xl,xr,l,mid);
	else if(xl > mid) return query(rs[y],rs[x],xl,xr,mid+1,r);
	else return query(ls[y],ls[x],xl,mid,l,mid) + query(rs[y],rs[x],mid+1,xr,mid+1,r);
}

void dfs(int x,int p){
	fa[x] = p; siz[x] = 1; dep[x] = dep[p]+1;
	for(int i = h[x],y;i;i = e[i].nxt){
		if((y = e[i].v) == p) continue;
		dfs(y,x); siz[x] += siz[y];
	}
}

void dfs(int x){
	dfn[x] = ++tim; update(rt[dfn[x]],rt[dfn[x]-1],dep[x],siz[x]-1);
	for(int i = h[x],y;i;i = e[i].nxt){
		if((y = e[i].v) == fa[x]) continue;
		dfs(y);
	}
}

void build(int &o,int l = 1,int r = n){
	o = ++nodenum;
	if(l == r) return; int mid = l+r>>1;
	build(ls[o],l,mid); build(rs[o],mid+1,r);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,q = in;
	for(int i = 1;i < n;i++){
		u = in,v = in; link(u,v); link(v,u);
	}build(rt[0]); dfs(1,0); dfs(1);
	while(q--){
		p = in,k = in;
		ans = (1ll * min(k,dep[p]-1) * (siz[p] - 1) + query(rt[dfn[p]+siz[p]-1],rt[dfn[p]-1],min(dep[p]+1,n),min(dep[p]+k,n)));
		printf("%lld\n",ans);
	}
	return 0;
}

